/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.xyplot.xyplot_view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

import br.ufmg.dees.insane.commons.InsaneProperties;
import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.command.CommandHolder;
import br.ufmg.dees.insane.commons.view.CmdButton;
import br.ufmg.dees.insane.commons.view.CmdMenu;
import br.ufmg.dees.insane.commons.view.CmdToggleButton;
import br.ufmg.dees.insane.commons.view.PrintableGridCanvas;
import br.ufmg.dees.insane.xyplot.xyplot_controller.XYPlotController;
import br.ufmg.dees.insane.xyplot.xyplot_model.XYPlot;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.AxisSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.BoundaryCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.CaptionCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.FitCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.GeneralSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.GridCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.GridSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.LastZoomCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.LimitsSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.SelectCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.SequenceSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.SnapCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.TextBoxSettingsCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.ZoomAllCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.ZoomCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.ZoomInCommand;
import br.ufmg.dees.insane.xyplot.xyplot_view.command.ZoomOutCommand;

/**
 * @author  Samuel Silva Penna
 */
public class InterfaceXYPlot extends JInternalFrame implements ActionListener, Observer {
	
    /**   */
	private static final long serialVersionUID = 1L;
	
	private XYPlotView view = new XYPlotView(this);
	private InsaneProperties properties = new InsaneProperties();
	private XYPlot model;
	
	//Main panels
	private JPanel drawArea = new JPanel();
	
	//Commands
	private Command zoomCmd = new ZoomCommand(this);
	private Command zoomInCmd = new ZoomInCommand(this);
	private Command zoomOutCmd = new ZoomOutCommand(this);
	private Command fitCmd = new FitCommand(this);
	private Command zoomAllCmd = new ZoomAllCommand(this);
	private Command lastZoomCmd = new LastZoomCommand(this);
	
	private Command gridCmd = new GridCommand(this);
	private Command boundCmd = new BoundaryCommand(this);
    private Command snapCmd = new SnapCommand(this);
	private Command genSettingsCmd = new GeneralSettingsCommand(this);
	private Command seqSettingsCmd = new SequenceSettingsCommand(this);
	private Command captionSettingsCmd = new CaptionCommand(this);
	private Command limSettingsCmd = new LimitsSettingsCommand(this);
	private Command gridSettingsCmd = new GridSettingsCommand(this);
	private Command axisSettingsCmd = new AxisSettingsCommand(this);	
	private Command textBoxSettingsCmd = new TextBoxSettingsCommand(this);	
	
	//Menu
	private JMenuBar menuBar = new JMenuBar();

	private JMenu menuView = new JMenu("View");
	private JMenu menuZoom = new JMenu("Zoom");
	private CmdMenu itemWindow = new CmdMenu("Window", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
	private CmdMenu itemZoomIn = new CmdMenu("In", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
	private CmdMenu itemZoomOut = new CmdMenu("Out", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
	private CmdMenu itemExtents = new CmdMenu("Extents", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
	private CmdMenu itemAll = new CmdMenu("All", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
	private CmdMenu itemLastZoom = new CmdMenu("Last", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
	
	private JMenu menuSettings = new JMenu("Settings");
	//private CmdMenu itemSettings = new CmdMenu("Settings", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
	private CmdMenu itemGenSettings = new CmdMenu("General Settings");
	private CmdMenu itemSeqSettings = new CmdMenu("Sequences Settings");
	private CmdMenu itemCaptionSettings = new CmdMenu("Caption Settings");
    private CmdMenu itemLimSettings = new CmdMenu("Limits Settings");
	private CmdMenu itemGridSettings = new CmdMenu("Grid Settings");
    private CmdMenu itemAxisSettings = new CmdMenu("Axis Settings");
	private CmdMenu itemTextBoxSettings = new CmdMenu("Text Box Settings");
	
	private JMenu menuHelp = new JMenu("Help");
	//private CmdMenu itemHelpTopics = new CmdMenu("Help Topics", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
	//private CmdMenu itemBugReport = new CmdMenu("Bug Report",  new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Bug16.gif")));
	//private CmdMenu itemAbout = new CmdMenu("About",  new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/About16.gif")));
	
	//Tools
	
	private JPanel toolPanel = new JPanel();
	
	private JToolBar zoomToolBar = new JToolBar();
	//private CmdButton redraw = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redraw16.gif")));
	private CmdButton fit = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
	private CmdButton zoom = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
	private CmdButton zoomIn = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
	private CmdButton zoomOut = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
	private CmdButton zoomAll = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
	private CmdButton zoomPrevious = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
    
    //Menu
    
    private JToolBar MenuBar = new JToolBar();
 /*   private CmdButton generalSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
    private CmdButton sequenceSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif"))); 
    private CmdButton captionSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif"))); 
    private CmdButton limitsSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
    private CmdButton gridSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
    private CmdButton axisSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
    private CmdButton textBoxSettings = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
*/
    
    private CmdButton generalSettings = new CmdButton("GenSets");
    private CmdButton sequenceSettings = new CmdButton("Sequences"); 
    private CmdButton captionSettings = new CmdButton("Caption"); 
    private CmdButton limitsSettings = new CmdButton("Limits");
    private CmdButton gridSettings = new CmdButton("Grid");
    private CmdButton axisSettings = new CmdButton("Axis");
    private CmdButton textBoxSettings = new CmdButton("TextBox");

    
    //In-Out Panel
	private JPanel inOutBar = new JPanel(new BorderLayout(6,0));
	
	private JPanel statusBar = new JPanel();
	
	private JTextField messageField = new JTextField(21);
	private JTextField coordField = new JTextField("Coords :",1);
	private JPanel state = new JPanel();
	private CmdToggleButton grid = new CmdToggleButton("Grid");
    private CmdToggleButton boundary = new CmdToggleButton("Boundary");
    private CmdToggleButton snap = new CmdToggleButton("Snap");

//*****************************************************************************

	/**
	 * The constructor method. <br>
	 * Calls the init() method throwing an exception.
	 */
	public InterfaceXYPlot() {
	    try {
            this.setFonts();
	        init();
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}

//*****************************************************************************

	/**
	 *  It's called by the constructor. <br>
	 *  Sets Panels, components and provides a window listener.
	 */
	private void init() throws Exception {
	
        this.setTitle("INSANE PLOT " + this.getProperties().getVersion());
		this.setMaximizable(true);
		this.setClosable(true);
        this.setSize(new Dimension(800,640));
		
        this.setFonts();
        
		this.messageField.setText("Escola de Engenharia da UFMG");

		toolPanel.setLayout(new BoxLayout(toolPanel, BoxLayout.X_AXIS));
		this.getContentPane().add(toolPanel, BorderLayout.NORTH);
		
		drawArea.setLayout(new BorderLayout());
		drawArea.setBorder(BorderFactory.createEmptyBorder(0,0,0,3));
		
		this.getContentPane().add(drawArea);
		
		//Setting Menus
		
		//Setting menu view
		menuView.setMnemonic(KeyEvent.VK_V);
		
		menuZoom.add(itemWindow);
		itemWindow.setCommand(zoomCmd);
		itemWindow.addActionListener(this);
		itemWindow.setMnemonic(KeyEvent.VK_W);
		itemWindow.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemZoomIn);
		itemZoomIn.setCommand(zoomInCmd);
		itemZoomIn.addActionListener(this);
		itemZoomIn.setMnemonic(KeyEvent.VK_I);
		itemZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemZoomOut);
		itemZoomOut.setCommand(zoomOutCmd);
		itemZoomOut.addActionListener(this);
		itemZoomOut.setMnemonic(KeyEvent.VK_O);
		itemZoomOut.setAccelerator(KeyStroke.getKeyStroke("MINUS"));
		
		menuZoom.add(itemAll);
		itemAll.setCommand(zoomAllCmd);
		itemAll.addActionListener(this);
		itemAll.setMnemonic(KeyEvent.VK_A);
		itemAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemExtents);
		itemExtents.setCommand(fitCmd);
		itemExtents.addActionListener(this);
		itemExtents.setMnemonic(KeyEvent.VK_E);
		itemExtents.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemLastZoom);
		itemLastZoom.setCommand(lastZoomCmd);
		itemLastZoom.addActionListener(this);
		itemLastZoom.setMnemonic(KeyEvent.VK_L);
		itemLastZoom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.SHIFT_MASK));
		
		menuView.add(menuZoom);
		menuZoom.setMnemonic(KeyEvent.VK_Z);
		itemLastZoom.addActionListener(this);
		
		//Setting menu settings
		menuSettings.setMnemonic(KeyEvent.VK_S);

		menuSettings.add(itemGenSettings);
		itemGenSettings.setCommand(genSettingsCmd);
		itemGenSettings.setMnemonic(KeyEvent.VK_G);
		itemGenSettings.addActionListener(this);
        
        menuSettings.add(itemSeqSettings);
        itemSeqSettings.setCommand(seqSettingsCmd);
        itemSeqSettings.setMnemonic(KeyEvent.VK_G);
        itemSeqSettings.addActionListener(this);
        
        menuSettings.add(itemCaptionSettings);
        itemCaptionSettings.setCommand(captionSettingsCmd);
        itemCaptionSettings.setMnemonic(KeyEvent.VK_G);
        itemCaptionSettings.addActionListener(this);

		menuSettings.add(itemLimSettings);
		itemLimSettings.setCommand(limSettingsCmd);
		itemLimSettings.setMnemonic(KeyEvent.VK_L);
		itemLimSettings.addActionListener(this);

		menuSettings.add(itemGridSettings);
		itemGridSettings.setCommand(gridSettingsCmd);
		itemGridSettings.setMnemonic(KeyEvent.VK_G);
		itemGridSettings.addActionListener(this);
		
		menuSettings.add(itemAxisSettings);
		itemAxisSettings.setCommand(axisSettingsCmd);
		itemAxisSettings.setMnemonic(KeyEvent.VK_G);
		itemAxisSettings.addActionListener(this);
		
		menuSettings.add(itemTextBoxSettings);
		itemTextBoxSettings.setCommand(textBoxSettingsCmd);
		itemTextBoxSettings.setMnemonic(KeyEvent.VK_G);
		itemTextBoxSettings.addActionListener(this);

		this.setJMenuBar(menuBar);
		
		//Setting tools
		
		//Setting zoom tool bar
		zoomToolBar.add(zoom);
		zoom.setToolTipText("Zoom Window");
		zoom.setCommand(zoomCmd);
		zoom.addActionListener(this);
		
		zoomToolBar.add(zoomIn);
		zoomIn.setToolTipText("Zoom In");
		zoomIn.setCommand(zoomInCmd);
		zoomIn.addActionListener(this);
		
		zoomToolBar.add(zoomOut);
		zoomOut.setToolTipText("Zoom Out");
		zoomOut.setCommand(zoomOutCmd);
		zoomOut.addActionListener(this);
		
		zoomToolBar.add(zoomAll);
		zoomAll.setToolTipText("Zoom All");
		zoomAll.setCommand(zoomAllCmd);
		zoomAll.addActionListener(this);
		
		zoomToolBar.add(fit);
		fit.setToolTipText("Zoom Extents");
		fit.setCommand(fitCmd);
		fit.addActionListener(this);
		
		zoomToolBar.add(zoomPrevious);
		zoomPrevious.setToolTipText("Zoom Last");
		zoomPrevious.setCommand(lastZoomCmd);
		zoomPrevious.addActionListener(this);
		
        //Setting menu bar
        MenuBar.add(generalSettings);
        generalSettings.setToolTipText("General Settings");
        generalSettings.setCommand(genSettingsCmd);
        generalSettings.addActionListener(this);
        
        MenuBar.add(sequenceSettings);
        sequenceSettings.setToolTipText("Sequences Settings");
        sequenceSettings.setCommand(seqSettingsCmd);
        sequenceSettings.addActionListener(this);
        
        MenuBar.add(captionSettings);
        captionSettings.setToolTipText("Caption Settings");
        captionSettings.setCommand(captionSettingsCmd);
        captionSettings.addActionListener(this);
        
        MenuBar.add(limitsSettings);
        limitsSettings.setToolTipText("Limits Settings");
        limitsSettings.setCommand(limSettingsCmd);
        limitsSettings.addActionListener(this);
        
        MenuBar.add(gridSettings);
        gridSettings.setToolTipText("Grid Settings");
        gridSettings.setCommand(gridSettingsCmd);
        gridSettings.addActionListener(this);
        
        MenuBar.add(axisSettings);
        axisSettings.setToolTipText("Axis Settings");
        axisSettings.setCommand(axisSettingsCmd);
        axisSettings.addActionListener(this);
        
        MenuBar.add(textBoxSettings);
        textBoxSettings.setToolTipText("Text Box Settings");
        textBoxSettings.setCommand(textBoxSettingsCmd);
        textBoxSettings.addActionListener(this);
   
		//Setting status bar
		
		statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS));
		
		messageField.setEditable(false);
		messageField.setBorder(BorderFactory.createEmptyBorder(2,3,1,3));
		coordField.setEditable(false);
		coordField.setBorder(BorderFactory.createEmptyBorder(2,3,1,3));
		state.setLayout(new GridLayout(1,3,1,1));
		
		grid.setMargin(new Insets(0,1,0,1));
		grid.setCommand(gridCmd);
		grid.addActionListener(this);
		state.add(grid);
        
        boundary.setMargin(new Insets(0,1,0,1));
        boundary.setCommand(boundCmd);
        boundary.addActionListener(this);
        state.add(boundary);
		
		snap.setMargin(new Insets(0,1,0,1));
		snap.setCommand(snapCmd);
		snap.addActionListener(this);
		state.add(snap);
		
		statusBar.add(coordField);
		statusBar.add(state);
		statusBar.add(messageField);
		
		inOutBar.add(BorderLayout.SOUTH, statusBar);
		
		this.getContentPane().add(inOutBar,BorderLayout.SOUTH);
		
		this.setCoord("" + 0.0, "" + 0.0);
		
		this.setInitialInterface();
		
		}

//******************************************************************************
	public void setFonts() {
		
		try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            Font fontCurrent = UIManager.getFont("Button.font");
            String name = fontCurrent.getName();
            
            //Creates similar font with the specified style and size
            FontUIResource fontResourceNew  = new FontUIResource(name, Font.PLAIN, 12);
            
            //Sets all items fonts
            UIManager.put("Button.font", fontResourceNew);
            UIManager.put("CheckBox.font", fontResourceNew);
            UIManager.put("CheckBoxMenuItem.font", fontResourceNew);
            UIManager.put("ColorChooser.font", fontResourceNew);
            UIManager.put("ComboBox.font", fontResourceNew);
            UIManager.put("DesktopIcon.font", fontResourceNew);
            UIManager.put("EditorPane.font", fontResourceNew);
            UIManager.put("InternalFrame.font", fontResourceNew);
            UIManager.put("Label.font", fontResourceNew);
            UIManager.put("List.font", fontResourceNew);
            UIManager.put("MenuBar.font", fontResourceNew);
            UIManager.put("Menu.font", fontResourceNew);
            UIManager.put("MenuItem.font", fontResourceNew);
            UIManager.put("OptionPane.font", fontResourceNew);
            UIManager.put("PasswordField.font", fontResourceNew);
            UIManager.put("PopupMenu.font", fontResourceNew);
            UIManager.put("ProgressBar.font", fontResourceNew);
            UIManager.put("RadioButton.font", fontResourceNew);
            UIManager.put("RadioButtonMenuItem.font", fontResourceNew);
            UIManager.put("ScrollPane.font", fontResourceNew);
            UIManager.put("TabbedPane.font", fontResourceNew);
            UIManager.put("TableHeader.font", fontResourceNew);
            UIManager.put("TextArea.font", fontResourceNew);
            UIManager.put("TextField.font", fontResourceNew);
            UIManager.put("TextPane.font", fontResourceNew);
            UIManager.put("TitledBorder.font", fontResourceNew);
            UIManager.put("ToggleButton.font", fontResourceNew);
            UIManager.put("ToolBar.font", fontResourceNew);
            UIManager.put("ToolTip.font", fontResourceNew);
            UIManager.put("Tree.font", fontResourceNew);
            UIManager.put("Viewport.font", fontResourceNew);

        }
        catch (Exception e){}
	}
	

//******************************************************************************

	/** Sets the Model.
	*  @param mdl The Model to be set.
	*/
	public void setModel(XYPlot mdl) {
		this.model = mdl;
		
		for(int i = 0; i < mdl.getSequencesList().size(); i++)
		((XYPlotViewState)this.view.getViewState()).addSequenceState(new SequenceViewState());
		
		((XYPlotController)this.view.getController()).setModel(mdl);
		((XYPlotController)this.view.getController()).setView(this.view);
		((XYPlotController)this.view.getController()).setDefaultView();
		
		((XYPlotView)this.view).getDrawingArea().setZoom(((XYPlotViewState)this.view.getViewState()).getLimits());
		((XYPlotView)this.view).getDrawingArea().setPrecision(((XYPlotViewState)this.view.getViewState()).getPrecision());
		((XYPlotView)this.view).getDrawingArea().setSnap(((XYPlotViewState)this.view.getViewState()).isSnapOn());
		((XYPlotView)this.view).getDrawingArea().setGridColor(((XYPlotViewState)this.view.getViewState()).gridColor);
		//((XYPlotView)this.view).getDrawingArea().setGrid(((XYPlotViewState)this.view.getViewState()).isGridOn());
		((XYPlotView)this.view).getDrawingArea().setGridIncs(((XYPlotViewState)this.view.getViewState()).getGridXInc(),
								((XYPlotViewState)this.view.getViewState()).getGridYInc());
		((XYPlotView)this.view).getDrawingArea().setBackground(((XYPlotViewState)this.view.getViewState()).bgcolor);
		
		((PrintableGridCanvas)this.view.getDrawingArea()).setDistort(true);
		this.view.getController().fit();
		this.view.getController().compose();
		
	}
	

	/**
	 * Returns the properties.
	 * @return  The properties.
	 * @uml.property  name="properties"
	 */
	public InsaneProperties getProperties() {
		return properties;
	}
	
	/**
	 * Returns the current controller.
	 * @return  The current controller.
	 * @uml.property  name="view"
	 */
	public XYPlotView getView() {
		return this.view;
	}
	
	//** Sets the initial Interface. */
	public void setInitialInterface() {
		menuBar.removeAll();
	    menuBar.add(menuView);
	   
	    menuBar.add(menuSettings);
	    menuBar.add(menuHelp);
	
	    toolPanel.removeAll();
	    toolPanel.add(MenuBar);
	    toolPanel.add(zoomToolBar);
        
       
	    grid.setEnabled(true);
	    boundary.setEnabled(true);
        snap.setEnabled(true);
	
	    ((XYPlotView)this.view).getDrawingArea().setSnap(true);
	    ((XYPlotViewState)this.view.getViewState()).setSnap(true);
		((XYPlotView)this.view).getDrawingArea().setSnap(true);
		((XYPlotView)this.view).getDrawingArea().setRepainting(true);
		((XYPlotView)this.view).getDrawingArea().repaint();
		
		this.setStateButtons();
	
		drawArea.removeAll();
		drawArea.add((JComponent)(((XYPlotView)this.view).getDrawingArea()), BorderLayout.CENTER);
		((XYPlotView)this.view).getDrawingArea().removeAllCommands();
		((XYPlotView)this.view).getDrawingArea().setClickedCommand(new SelectCommand(this));
		((XYPlotView)this.view).getDrawingArea().setCursor();
		
		drawArea.repaint();
		drawArea.updateUI();
		
		this.setCoord("" + 0.0, "" + 0.0);

		this.repaint();
	}

//*****************************************************************************

	/** Adds a Command to the undoList.
	 * @param cmd a the desired command
	 **/
	public void addToUndo(Command cmd) {
		
	}

//*****************************************************************************

	/** Adds a Command to the redoList.
	 * @param cmd a the desired command
	 */
	public void addToRedo(Command cmd) {
	
	}

//*****************************************************************************

	/** Disables the redo command.*/
	public void nothingToRedo() {
		
	}

//*****************************************************************************

	/** Disables the undo command.*/
	public void nothingToUndo() {
		
	}

//*****************************************************************************

	/**
	* Sets the Status Bar coord text.
	* @param x The first "X" coordinate.
	* @param y The second "Y" coordinate.
	*/
	public void setCoord(String x, String y) {
		this.coordField.setText("Coords: " + x + ", " + y);
	}

//*****************************************************************************

	/**
	* Sets the Status Bar message.
	* @param str The text to be shown
	*/
	public void setMessage(String str) {
		this.messageField.setText(str);
	}

//*****************************************************************************

	/** Method which executes the desired action to each command.*/
	public void actionPerformed(ActionEvent evt) {
		CommandHolder obj = (CommandHolder)evt.getSource();
		obj.getCommand().execute();
	}

//*****************************************************************************

	/** Sets the StateButtons of this Interface. */
	public void setStateButtons() {
		grid.setSelected(((XYPlotViewState)this.view.getViewState()).isGridOn());
		boundary.setSelected(((XYPlotViewState)this.view.getViewState()).isBoundaryOn());
        snap.setSelected(((XYPlotViewState)this.view.getViewState()).isSnapOn());
	}

	public void update(Observable arg0, Object arg1) {
		try{
			//this.setModel( ((XYPlotPathPostp)arg0).getXYPlotModel());
			this.getView().getController().fit();
		    this.getView().getDrawingArea().repaint();
		}catch (Exception e){
			
		}
		
	}

	/**
	 * The method return the model.
	 * @return Returns The model.
	 */
	public XYPlot getModel() {
		return model;
	}

//*****************************************************************************

}
